//
//  HEItemBtnView.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/2.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEItemBtnView.h"

@interface HEItemBtnView ()

@property (nonatomic, strong) UILabel *titleLb;

@end

@implementation HEItemBtnView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initUI];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectBtnClick)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)initUI {
    
    _imageView = [UIImageView new];
    _imageView.image = IMAGE_NAMED(@"add_report");
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:_imageView];
    
    _titleLb = [UILabel new];
    _titleLb.font = DYFont(15);
    _titleLb.textAlignment = NSTextAlignmentCenter;
    _titleLb.textColor = CNavDargGrayColor;
    [self addSubview:_titleLb];

    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.centerX.equalTo(self);
        make.width.offset(30);
        make.height.offset(27);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_imageView.mas_bottom).mas_offset(5);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self).mas_offset(5);
    }];
}

- (void)resetLayoutWithWidth:(CGFloat)width height:(CGFloat)height {
    [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.centerX.equalTo(self);
        make.width.offset(width);
        make.height.offset(height);
    }];
    [self.superview layoutIfNeeded];
}

- (void)selectBtnClick {
    if (self.selectBlock) {
        self.selectBlock(self);
    }
}


#pragma mark -
- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    _titleLb.textColor = titleColor;
}

- (void)setTitleFont:(UIFont *)titleFont {
    _titleFont = titleFont;
    _titleLb.font = titleFont;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    _titleLb.text = _title;
}

- (void)setImageName:(NSString *)imageName {
    _imageView.image = IMAGE_NAMED(imageName); 
}

@end
